﻿using BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace QuanLyCongNo.Controllers
{
    public class SanPhamController : Controller
    {
        DataContext db = new DataContext();
       
        public ActionResult Index()
        {
            return View(db.GetListSanPham());
        }

      
        public ActionResult Details(int id)
        {
            return View();
        }

        [HttpGet]
        public ActionResult Create()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Create(SanPham sp)
        {
            try
            {

                db.InsertSanPham(sp);
                ModelState.AddModelError("", "Cập nhật thành công !");
                return RedirectToAction("Index");
            }
            catch
            {
                return View("Index", sp);
            }
        }

     
        public ActionResult Edit(int id)
        {
            return View();
        }

     
        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
              

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

     
        public ActionResult Delete(int id)
        {
            return View();
        }

       
        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
              

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
